home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 22 / Amiga Format AFCD22 (Jan 1998, Issue 106).iso / -in_the_mag- / converters / graphics / netpbm / hpcdtoppm.0.6 / src / output.c < prev    next >
C/C++ Source or Header  |  1997-11-16  |  5KB  |  196 lines

  1. /* hpcdtoppm (Hadmut's pcdtoppm) v0.6
  2. *  Copyright (c) 1992, 1993, 1994 by Hadmut Danisch (danisch@ira.uka.de).
  3. *  Permission to use and distribute this software and its
  4. *  documentation for noncommercial use and without fee is hereby granted,
  5. *  provided that the above copyright notice appear in all copies and that
  6. *  both that copyright notice and this permission notice appear in
  7. *  supporting documentation. It is not allowed to sell this software in 
  8. *  any way. This software is not public domain.
  9. */
  10.  
  11. #include "hpcdtoppm.h"
  12.  
  13.  
  14.  
  15.  
  16. static void flip_corr(dim w,dim h,uBYTE **ptr,sdim *ystep,sdim *xstep)
  17.  {if(flvert) 
  18.    { (*ptr) += (h-1)* (*ystep);
  19.      (*ystep) = -(*ystep);
  20.    }
  21.  
  22.   if(flhori)
  23.    {(*ptr) += (w-1)* (*xstep);
  24.     (*xstep) = -(*xstep);
  25.    }
  26.  }
  27.  
  28.  
  29.  
  30.  
  31. static void call_1plane(OUT1PL proc, FILE *fout,
  32.                         dim w,    dim h,uBYTE * ptr,
  33.                         sdim zeil, sdim pix) 
  34.  {
  35.   flip_corr(w,h,&ptr,&zeil,&pix);
  36.   (*proc)(fout,w,h,ptr,zeil,pix);
  37.  }
  38.  
  39.  
  40.  
  41. static void do_1plane(OUT1PL proc, FILE *fout,
  42.                       dim w,dim h,implane *g,enum TURNS t)
  43.  {
  44.    switch(t)
  45.     {case T_NONE: call_1plane(proc,fout,w,h,g->im,g->mwidth,1);
  46.                   break;
  47.      case T_RIGHT:call_1plane(proc,fout,h,w,g->im + g->mwidth * ( g->iheight - 1) , 1 , -(g->mwidth));
  48.                   break;
  49.      case T_LEFT: call_1plane(proc,fout,h,w,g->im + g->iwidth - 1 , -1 , (g->mwidth));
  50.                   break; 
  51.      case T_HEAD: call_1plane(proc,fout,w,h,g->im + g->iwidth - 1 + g->mwidth * ( g->iheight - 1)  , -(g->mwidth) , -1);
  52.                   break;     
  53.      default:error(E_INTERN);
  54.     }
  55.  
  56.  }
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. static void call_3plane(OUT3PL proc, FILE *fout,  dim w,dim h, 
  65.                         uBYTE *rptr,sdim rzeil,sdim rpix,  
  66.                         uBYTE *gptr,sdim gzeil,sdim gpix,  
  67.                         uBYTE *bptr,sdim bzeil,sdim bpix) 
  68.  {
  69.   flip_corr(w,h,&rptr,&rzeil,&rpix);
  70.   flip_corr(w,h,&gptr,&gzeil,&gpix);
  71.   flip_corr(w,h,&bptr,&bzeil,&bpix);
  72.  
  73.   (*proc)(fout,w,h,rptr,rzeil,rpix,gptr,gzeil,gpix,bptr,bzeil,bpix );
  74.  }
  75.  
  76.  
  77. static void do_3plane(OUT3PL proc,FILE *fout,dim w,dim h,
  78.                       implane *r,implane *g,implane *b,
  79.                       enum TURNS t)
  80.  {
  81.    switch(t)
  82.     {case T_NONE: call_3plane(proc,fout,w,h,r->im,r->mwidth,1,
  83.                                             g->im,g->mwidth,1,
  84.                                             b->im,b->mwidth,1);
  85.                   break;     
  86.      case T_RIGHT:call_3plane(proc,fout,h,w,r->im + r->mwidth * ( r->iheight - 1) , 1 , -(r->mwidth),
  87.                                             g->im + g->mwidth * ( g->iheight - 1) , 1 , -(g->mwidth),
  88.                                             b->im + b->mwidth * ( b->iheight - 1) , 1 , -(b->mwidth));
  89.                   break;     
  90.      case T_LEFT: call_3plane(proc,fout,h,w,r->im + r->iwidth - 1 , -1 , (r->mwidth),
  91.                                             g->im + g->iwidth - 1 , -1 , (g->mwidth),
  92.                                             b->im + b->iwidth - 1 , -1 , (b->mwidth));
  93.                   break;           
  94.      case T_HEAD: call_3plane(proc,fout,w,h,r->im + r->iwidth - 1 + r->mwidth * ( r->iheight - 1)  , -(r->mwidth) , -1,
  95.                                             g->im + g->iwidth - 1 + g->mwidth * ( g->iheight - 1)  , -(g->mwidth) , -1,
  96.                                             b->im + b->iwidth - 1 + b->mwidth * ( b->iheight - 1)  , -(b->mwidth) , -1);
  97.                   break;     
  98.      default:error(E_INTERN);
  99.     }
  100.  
  101.  }
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. void writepicture(FILE *fout, sizeinfo *si, 
  114.                   implane *r,implane *g,implane *b,
  115.                   enum TURNS t)
  116.  {dim w,h;
  117.  
  118.   w=si->imhlen;
  119.   h=si->imvlen;
  120.  
  121.   melde("writepicture\n");
  122.      if((!r) || (r->iwidth != w ) || (r->iheight != h) || (!r->im)) error(E_INTERN);
  123.   
  124.   if(!monochrome)
  125.    {
  126.      if((!g) || (g->iwidth != w ) || (g->iheight != h) || (!g->im)) error(E_INTERN);
  127.      if((!b) || (b->iwidth != w ) || (b->iheight != h) || (!b->im)) error(E_INTERN);
  128.    }
  129.  
  130.   switch(outfor)
  131.    {case O_YCC:
  132.     case O_PPM:  do_3plane(write_ppm     ,fout,w,h,r,g,b,t); break;
  133.     case O_PS:   do_3plane(write_psrgb   ,fout,w,h,r,g,b,t); break;
  134.     case O_EPS:  do_3plane(write_epsrgb  ,fout,w,h,r,g,b,t); break;
  135.  
  136.     case O_PGM:  do_1plane(write_pgm     ,fout,w,h,r,t);     break;
  137.     case O_PSG:  do_1plane(write_psgrey  ,fout,w,h,r,t);     break;
  138.     case O_EPSG: do_1plane(write_epsgrey ,fout,w,h,r,t);     break;
  139.     case O_PSD:  do_1plane(write_psdith  ,fout,w,h,r,t);     break;
  140.     case O_EPSD: do_1plane(write_epsdith ,fout,w,h,r,t);     break;
  141.     case O_JPEG: do_3plane(write_jpeg    ,fout,w,h,r,g,b,t);     break;
  142.     default: error(E_INTERN);
  143.    }
  144.  
  145.  
  146.  }
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156. struct ph1 
  157.  {char  id1[8];
  158.   uBYTE ww1[14];
  159.   char  id2[20];
  160.   char  id3[4*16+4];
  161.   short ww2;
  162.   char  id4[20];
  163.   uBYTE ww3[2*16+1];
  164.   char  id5[4*16];
  165.   uBYTE idx[11*16];
  166.  } ;
  167.  
  168.  
  169. void druckeid(void)
  170. {struct ph1 *d;
  171.  char ss[100];
  172.  
  173.  d=(struct ph1 *)sbuffer;
  174.  
  175. #define dr(feld,kennung)   \
  176.      strncpy(ss,feld,sizeof(feld));\
  177.      ss[sizeof(feld)]=0;\
  178.      fprintf(stderr,"%s: %s \n",kennung,ss);
  179.  
  180.  
  181. dr(d->id1,"Id1")
  182. dr(d->id2,"Id2")
  183. dr(d->id3,"Id3")
  184. dr(d->id4,"Id4")
  185. dr(d->id5,"Id5")
  186.  
  187. #undef dr 
  188.  
  189. }
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.